﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Infancy.Core.Validation;

namespace Infancy.Core.Entities {
    public abstract class AutoValidateEntityBase<TEntity> : ValidateEntityBase<TEntity>, IDataErrorInfo
        where TEntity : IEntity {
        private ValidatedResult validateResult;

        #region IDataErrorInfo Members

        public string Error {
            get { return String.Empty; }
        }

        public string this[string columnName] {
            get {
                if (validateResult == null) {
                    validateResult = Validate();
                }
                string errorMessage;
                if (!validateResult.Errors.TryGetValue(columnName, out errorMessage)) {
                    errorMessage = String.Empty;
                }
                return errorMessage;
            }
        }

        #endregion
    }
}
